package server;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by swallow on 2021/3/17.
 */
public class Host {
    private String docBase;
    private Map<String, Context> map = new HashMap<>();

    public Host(String docBase) {
        this.docBase = docBase;
        File file = new File(docBase);
        for (File appDir : file.listFiles()) {
            Context context = new Context(appDir);
            String name = appDir.getName();
            map.put(name, context);
        }
    }

    public Wapper getWapper(Request request) {
        Context context = map.get(request.getContext());
        if (context == null) return null;
        return context.map.get(request.getUrl());
    }

    public String getDocBase() {
        return docBase;
    }

    public void setDocBase(String docBase) {
        this.docBase = docBase;
    }

    public Map<String, Context> getMap() {
        return map;
    }

    public void setMap(Map<String, Context> map) {
        this.map = map;
    }
}
